﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace DHTMLX.Export.Excel
{
    public class ExportExcelController : Controller
    {
        //
        // GET: /ExportExcel/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult ExportInvoiceGridToExcel()
        {
            String fileName = "InvoiceReport_" + DateTime.Today.ToString("yyyyMMdd") + ".xlsx";

            var generator = new ExcelWriter();
            var xml = this.Request.Form["grid_xml"];
            xml = this.Server.UrlDecode(xml);
            var stream = generator.Generate(xml);
            return File(stream.ToArray(), generator.ContentType, fileName);

        }

        public ActionResult ExportQuotationGridToExcel()
        {
            String fileName = "QuotationReport_" + DateTime.Today.ToString("yyyyMMdd") + ".xlsx";

            var generator = new ExcelWriter();
            var xml = this.Request.Form["grid_xml"];
            xml = this.Server.UrlDecode(xml);
            var stream = generator.Generate(xml);
            return File(stream.ToArray(), generator.ContentType, fileName);

        }

        public ActionResult ExportWOGridToExcel()
        {
            String fileName = "WorkOrderReport_" + DateTime.Today.ToString("yyyyMMdd") + ".xlsx";

            var generator = new ExcelWriter();
            var xml = this.Request.Form["grid_xml"];
            xml = this.Server.UrlDecode(xml);
            var stream = generator.Generate(xml);
            return File(stream.ToArray(), generator.ContentType, fileName);

        }
    }
}
